{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from surprise import SVD"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from surprise import Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from surprise.model_selection import cross_validate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Load the movielens-100k dataset (download it if needed).\n",
    "data = Dataset.load_builtin('ml-100k')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Use the famous SVD algorithm.\n",
    "algo = SVD()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Evaluating RMSE, MAE of algorithm SVD on 5 split(s).\n",
      "\n",
      "                  Fold 1  Fold 2  Fold 3  Fold 4  Fold 5  Mean    Std     \n",
      "RMSE (testset)    0.9377  0.9321  0.9358  0.9402  0.9437  0.9379  0.0039  \n",
      "MAE (testset)     0.7362  0.7352  0.7382  0.7409  0.7444  0.7390  0.0033  \n",
      "Fit time          6.22    6.20    6.19    6.21    6.19    6.20    0.01    \n",
      "Test time         0.24    0.23    0.23    0.24    0.23    0.23    0.00    \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'fit_time': (6.222760915756226,\n",
       "  6.20469331741333,\n",
       "  6.1879661083221436,\n",
       "  6.211632966995239,\n",
       "  6.190063238143921),\n",
       " 'test_mae': array([ 0.73621287,  0.73522234,  0.73822487,  0.74086986,  0.74439669]),\n",
       " 'test_rmse': array([ 0.93770033,  0.93214669,  0.93578921,  0.94017198,  0.94369227]),\n",
       " 'test_time': (0.23740530014038086,\n",
       "  0.23142600059509277,\n",
       "  0.23230195045471191,\n",
       "  0.2380833625793457,\n",
       "  0.23026537895202637)}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Run 5-fold cross-validation and print results.\n",
    "cross_validate(algo, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
